package com.sunl.mall.ali.mq.util;

import com.aliyun.openservices.ons.api.PropertyKeyConst;

import java.util.Properties;

/**
 * 获取消费者G_ID和生产者G_ID
 */
public class MqUtil {
    /**
     * 消费者id
     * <p>
     * 早期版本配置key {@link com.aliyun.openservices.ons.api.PropertyKeyConst#ConsumerId}
     * 新版本的配置key {@link com.aliyun.openservices.ons.api.PropertyKeyConst#GROUP_ID}
     *
     * @param properties properties
     * @return consumerId
     */
    public static String getConsumerId(Properties properties) {
        return properties.getProperty(PropertyKeyConst.GROUP_ID, properties.getProperty(PropertyKeyConst.ConsumerId));
    }

    /**
     * {@link com.aliyun.openservices.ons.api.PropertyKeyConst#ProducerId}
     * {@link com.aliyun.openservices.ons.api.PropertyKeyConst#GROUP_ID}
     *
     * @param properties properties
     * @return productId
     */
    public static String getProductId(Properties properties) {
        return properties.getProperty(PropertyKeyConst.GROUP_ID, properties.getProperty(PropertyKeyConst.ProducerId));
    }

}
